from django_cron import cronScheduler, Job
from mails.models import Dmail
import datetime

class CheckUnsent(Job):
    run_every = 10
    def job(self):
        sendUnsended()

cronScheduler.register(CheckUnsent)

def sendUnsended():
    print "hi"
    l = Dmail.objects.filter(sent=False,date__lt=datetime.datetime.today()) 
    for dmail in l:
        dmail.send()
    l = Dmail.objects.filter(sent=False,date=datetime.datetime.today(),time__lte=datetime.datetime.now().time())
    for dmail in l:
        dmail.send()

        

    
    
